//
//  CHTipView.m
//  Chehu_User
//
//  Created by 黄卫 on 17/2/24.
//  Copyright © 2017年 huangwei. All rights reserved.
//

#import "GJTipView.h"

@interface GJTipView ()

@property (nonatomic, copy) void(^touchBlock)();

@end

@implementation GJTipView

/**
 *  根据类型显示提示view
 */
- (instancetype)initWithFrame:(CGRect)frame tipImage:(UIImage *)image mianTip:(NSString *)mianTipStr detailTip:(NSString *)detailTip touchBlock:(void(^)())block
{
    self = [super initWithFrame:frame];
    if (self) {
        self.touchBlock = block;
        self.backgroundColor = Color_BackGround;
        
        CGFloat tipImageX = (frame.size.width-image.size.width)/2;
        CGFloat tipImageY = (frame.size.height-image.size.height-45)/2;
        
        UIButton *tipImageBtn = nil;
        if (image) {
            tipImageBtn = [[UIButton alloc] init];
            [tipImageBtn setImage:image forState:0];
            tipImageBtn.frame = CGRectMake(tipImageX, tipImageY, image.size.width, image.size.height);
            [tipImageBtn addTarget:self action:@selector(touchTipView) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:tipImageBtn];
        }
        
        UIButton *tipbutton = nil;
        if (mianTipStr) {
            CGFloat tipStrY = CGRectGetMaxY(tipImageBtn.frame) + 25;
            tipbutton = [[UIButton alloc] initWithFrame:CGRectMake(0, tipStrY, frame.size.width, 20)];
            [tipbutton addTarget:self action:@selector(touchTipView) forControlEvents:UIControlEventTouchUpInside];
            [tipbutton setTitleColor:Color_grayFont forState:0];
            [tipbutton setTitleColor:Color_BlackFont forState:1];
            tipbutton.titleLabel.font = FontCustomSize(14);
            [tipbutton setTitle:mianTipStr forState:0];
            [self addSubview:tipbutton];
            
            if (!tipImageBtn) {
                tipbutton.center = self.center;
            }
        }
        
        if (detailTip && tipbutton) {
            CGFloat checkLabelY = CGRectGetMaxY(tipbutton.frame) + 10;
            UIButton *detailButton = [[UIButton alloc] initWithFrame:CGRectMake(0, checkLabelY, Screen_Width, 20)];
            [detailButton addTarget:self action:@selector(touchTipView) forControlEvents:UIControlEventTouchUpInside];
            [detailButton setTitleColor:Color_grayFont forState:0];
            [detailButton setTitleColor:Color_BlackFont forState:1];
            detailButton.titleLabel.font = FontCustomSize(14);
            [tipbutton setTitle:detailTip forState:0];
            [self addSubview:detailButton];
        }
    }
    return self;
}



/**
 *  移除当前View
 */
- (void)touchTipView
{
    if (self.touchBlock) {
        self.touchBlock();
    }
    [self removeFromSuperview];
}

@end
